<!-- Author: Mary Llenos --> 
<!-- Last Modified: 11 Sep 2012 --> 
<!-- Handles posting and editing accommodation records in the dabase --> 
<?php session_start();
include("db.php"); 
$_SESSION['msg1'] = "Logout";
$_SESSION['msg2'] = "Welcome, ".$_REQUEST['fname']."! | ";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="Templates/Assn3_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>www.onestopjcu template</title>
<?php 
$action = $_GET['do'];

switch($action) {
	case "newpost":
		newpost();
	break;
	case "editpost":
		editpost();
	break;
	default: 
		//
}

function newpost() {
	if ( isset($_REQUEST['signup']) ) 
	{
		$connection=mysql_connect("localhost", "root", ""); 

		mysql_select_db("onestopjcu"); 
		if($_SESSION['upload'] == true) {
 	    	$sqlstr = mysql_query("select * from photoupload") or die(mysql_error());
			if (mysql_numrows($sqlstr) != 0) {
			while ($row = mysql_fetch_array($sqlstr)) {
				$filename=$row['photo_filename'];
			}
		}
		$_SESSION['upload'] = false;
	} else {
	//if user did not upload any picture, assign the no image picture filename
	$filename = "noimage.jpg";
	}
	$myDB = new db();

	$insert_query ="INSERT INTO  `onestopjcu`.`accommodation` (
`accom_id` ,
`mem_id` ,
`accom_category` ,
`accom_descrip` ,
`accom_date` ,
`accom_district` ,
`accom_postal` ,
`accom_price` ,
`accom_filename`
)
VALUES (
NULL ,  '".$_SESSION['visitorID']."',  '".$_REQUEST['category']."',  '".$_REQUEST['description']."', 
CURRENT_TIMESTAMP ,  '".$_REQUEST['district']."',  '".$_REQUEST['postal']."',  '".$_REQUEST['price']."',  '".$filename."'
)";

	$result = $myDB->sendSQLStatement($insert_query);	
	$_SESSION['success'] = true;		
	header("location: accommodation.php");
	} else {
		header("location: Accom_newpost.php");
	}
}

function editpost() {
	if ( isset($_REQUEST['signup']) ) 
	{
		$connection=mysql_connect("localhost", "root", ""); 
		//user changed a new picture
		if($_SESSION['upload']=="change"){ 
			mysql_select_db("onestopjcu"); 
  			$sqlstr = mysql_query("select * from photoupload") or die(mysql_error());
			if (mysql_numrows($sqlstr) != 0) {
			while ($row = mysql_fetch_array($sqlstr)) {
				$filename=$row['photo_filename'];
			}
		}
	
		$_SESSION['upload']="false";
	} else {
		$filename=$_REQUEST['imgName'];
	}
		$myDB = new db();
		unset($_SESSION['accomid']);
		$id = $_REQUEST['id'];
		$result = $myDB->sendSQLStatement("UPDATE `accommodation` SET `accom_category` ='".$_REQUEST['category']."',`accom_descrip` ='".$_REQUEST['description']."', `accom_district` ='".$_REQUEST['district']."', `accom_postal` ='".$_REQUEST['postal']."', `accom_price` ='".$_REQUEST['price']."',`accom_filename` ='".$filename."' WHERE `accommodation`.`accom_id` = '".$id."'")or die("Query failed: " . mysql_error());	

		$_SESSION['success'] = true;			
  		header("location: editviewpost.php");
	} else {
		echo "window.history.back();";
	}
}

?>
<!-- InstanceEndEditable -->

	<link href="Assn3_CSS.css" rel="stylesheet" type="text/css" />
	<link type="text/css" href="New folder/menu.css" rel="stylesheet" />
    <script type="text/javascript" src="New folder/jquery.js"></script>
    <script type="text/javascript" src="New folder/menu.js"></script>
    <script>
document.write('<div style="display:none;"><a href="http://apycom.com/">jQuery Menu by Apycom</a></div>');
</script>
</head>

<body>
<div class="container" id="top">

<div class="heads"><!-- heads -->
<div class="welcome">
<table>
<tr>
<td>
<?php  echo $_SESSION['msg2']; ?>
<a href="register.php"><?php  echo $_SESSION['msg1']; ?></a>
</td>
</tr>
</table>
</div>
</div>

<div id="menu">
  
  <ul class="menu1">
  		<li><a href="home.php" class="parent"><span>Home</span></a></li>
	
		<li><a href="member.php" class="parent"><span>Member</span></a>
			<div><ul>
    			<li><a href="member.php"><span>Member</span></a></li>            
				<li><a href="register.php"><span><?php  echo $_SESSION['msgMember']; ?></span></a></li>
    		
    		</ul></div>
		</li>           
        	
		<li><a href="Accommodation.php" class="parent"><span>Accommodation</span></a>
			<div><ul>           
				<li><a href="accommodation.php"><span>Search Room</span></a></li>
        		<li><a href="Accom_newpost.php"><span>Post New Advitisement</span></a></li>
            	<li><a href="viewpost.php"><span>View Your Posts</span></a></li>
       		
    		</ul></div>
		</li>	


		<li><a href="shopping.php" class="parent"><span>Selling Books</span></a>
			<div><ul>           
				<li><a href="shopping.php"><span>Browse Books</span></a></li>
           		<li><a href="shopping_newpost.php"><span>Post New Books</span></a></li>
             	<li><a href="view_cart.php"><span>View Your Carts</span></a></li>
       		   		
    		</ul></div>
	</li>



		<li><a href="announcement.php" class="parent"><span>Announcement</span></a>
			<div><ul>
    			<li><a href="announcement.php"><span>Announcement</span></a></li>           
        		<li><a href="new_announce.php"><span>Post New Announcement</span></a></li> 
            	<li><a href="viewmypost.php"><span>View Your Posts</span></a></li> 
                
    		</ul></div>
	</li>


        <li class="last"><a href="aboutus.php"><span>About us</span></a>
        	<div><ul>
            	<li><a href="feedback.php"><span>Feedback</span></a></li>
            </ul></div>
        
        </li>


<!-- InstanceBeginEditable name="phplogin" -->

<!-- InstanceEndEditable -->


</div><!-- menu -->


<!-- InstanceBeginEditable name="main" -->
<div class="main">
<br/>
<br/>
<h3 align="center">Thank you for registering with us.  Please enjoy our services!</h3>
</div><!-- main -->
<!-- InstanceEndEditable -->


<div class="footer"> 
<div style="margin-left:10px; float:left; font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px; color:#FFF; width:430px; height:12px; margin-top:16px;">Copyright &copy; 2012 www.onestopjcu.com
</div>

<div style="margin-left:50px; float:left; font-family:Arial, Helvetica,sans-serif; font-weight:bold; font-size:11px; width:100px; height:12px; margin-top:16px;"><a href="#top" style="color:#FFF; text-decoration: none;">Return to Top</a>
</div>

<ul>
<li><a href="feedback.php">Feedback</a></li>
<li><a href="FAQ.php">FAQ</a></li>
<li><a href="aboutus.php" style="margin-right:24px;">About Us</a></li>
<li><a href="aboutus.php" style="margin-right:24px;">Contact Us</a></li>
</ul>




</div><!-- footer -->
</div><!-- container -->
</body>
<!-- InstanceEnd --></html>
